<?php
session_start();
if (isset($_POST['op']) && !empty($_POST['op'])){
    if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"])=="xmlhttprequest"){
    include '../c/config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    $openid=addslashes(trim($_POST['op']));
    $type=addslashes(trim($_POST['t']));
    $typeArr= array(
      'gonggaoclose' => '公告栏-进入按钮',
      'zhibojian' => '游戏界面-直播间',
      'viewpaihangbang' => '游戏界面-排行榜',
      'gamegonggao'=>'游戏界面-公告',
      'gonggao' => '公告页浏览',
      'startgame' =>'开始按钮',
      'jixuzuozhan'=>'继续作战',
      
       
    );
  $sql="select zslink from `zsu_user_log` where openid='".$openid."'  limit 0,1 ";
	$query = $mysqli->query($sql);
  $zslink='';
	if($query->num_rows>0){
       $getZsu=$query->fetch_assoc();
       $zslink=$getZsu['zslink'];  
	}
  $name='';
  if (isset($typeArr[$type])) {
    $name=$typeArr[$type];
  }
$mysqli->query("insert into zsu_click_log(openid,lei,name,zslink,createtime) values('".$openid."','".$type."','".$name."','".$zslink."','".date("Y-m-d H:i:s")."') ");

  if ($_POST["cookieid"]) {
      $sql="select statime from `zsu_user_time` where openid='".$openid."' and dayid='".$_POST["cookieid"]."'  limit 0,1 ";
      $query = $mysqli->query($sql);
      if($query->num_rows>0){
        $getData=$query->fetch_assoc();
        $endTime=date("Y-m-d H:i:s");
        $cha=strtotime($endTime) - strtotime($getData['statime']);
        if ($cha < 0) {
          $cha=0;
        }
        $mysqli->query("update zsu_user_time set endtime='".$endTime."', cha='".$cha."' where openid='".$openid."' and dayid='".$_POST["cookieid"]."'  ");
      }
  }

    echo 2;
   
    $mysqli->close();
   }
}
?>